// 密码
const validatePassword = async (rule, value) => {
    if (value && value.length < 6) {
        // 验证失败
        return Promise.reject('密码长度不能小于6位')
    } else {
        // 验证通过
        return Promise.resolve()
    }
};

// 手机号码
const validateUserPhone = async (rule, value) => {
    if (value && value.length !== 11) {
        // 验证失败
        return Promise.reject('手机号码长度必须位11位')
    } else {
        // 验证通过
        return Promise.resolve()
    }
};

// 账号
const validateUserNumber = async (rule, value) => {
    if (value && value.length < 11) {
        // 验证失败
        return Promise.reject('用户账号长度不能小于11 位')
    } else {
        // 验证通过
        return Promise.resolve()
    }
};

// 邮箱
const validateUserEmail = async (rule, value) => {
    const emailPattern = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    const isEmailValid = (email) => {
        return emailPattern.test(email);
    };
    if (value && isEmailValid(value)) {
        // 验证通过
        return Promise.resolve()
    } else {
        // 验证失败
        return Promise.reject('电子邮件格式不正确')
    }
};


const rules = [
    [
        {required: true, message: '账号不能为空!'},
        {validator: validateUserNumber}
    ],
    [
        {required: true, message: '密码不能为空!'},
        {validator: validatePassword}
    ],
    [
        {required: true, message: '昵称不能为空!'}
    ],

    [
        {required: true, message: '手机不能为空!'},
        {validator: validateUserPhone}
    ],
    [
        {required: true, message: '邮箱不能为空!'},
        {validator: validateUserEmail}
    ],
    [
        {required: true, message: '性别不能为空!'}
    ],

]

export default rules
